package com.hg.chapter1;

import com.hg.chapter1.aop.AspectConfig;
import com.hg.chapter1.aop.annotation.MyService;
import com.hg.chapter1.aop.method.MethodService;
import com.hg.chapter1.config.Bean1;
import com.hg.chapter1.config.Bean2;
import com.hg.chapter1.config.MyConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

@SpringBootApplication
public class Chapter1Application {

    public static void main(String[] args) {
//        SpringApplication.run(Chapter1Application.class, args);
        AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext(AspectConfig.class);
//        AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext(MyConfig.class);

        //by type
//        Bean1 bean = context.getBean(Bean1.class);
//        System.out.println(bean.getMsg());

        //by name
//        Bean2 bean2 = (Bean2)context.getBean("bean2");
//        bean2.say();

        MyService aspect1 = context.getBean(MyService.class);
        MethodService aspect2 = context.getBean(MethodService.class);

        aspect1.add();
        aspect2.add();

        context.close();
    }

}
